package com.roy.royminidao.common.framework.lang.db;

import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.support.DaoSupport;
import org.springframework.util.Assert;

public class AbstractDaoSupport extends DaoSupport{

    private SqlSessionExecutor sqlSession;

    private SqlSessionFactory sqlSessionFactory;

    /**
     * 设置SqlSessionFactory，并实例化SqlSessionExecutor
     * 
     * @param sqlSessionFactory
     */
    @Autowired
    public final void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
        this.sqlSessionFactory = sqlSessionFactory;
        this.sqlSession = new SqlSessionExecutor(this.sqlSessionFactory);
    }

    /**
     * 获取SqlSessionExecutor
     * 
     * @return
     */
    public final SqlSessionExecutor getSqlSession() {
        return this.sqlSession;
    }

    /*
     * (non-Javadoc)
     * @see org.springframework.dao.support.DaoSupport#checkDaoConfig()
     */
    @Override
    protected void checkDaoConfig() throws IllegalArgumentException {
        Assert.notNull(this.sqlSession, "Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required");
    }
}
